package com.muqi.app.user.widget;

import java.util.Calendar;

import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.muqi.app.qlearn.student.R;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RecordDateEntry extends RelativeLayout implements DatePickerDialog.OnDateSetListener{
	public static final String DATEPICKER_TAG = "datepicker";
	private TextView mTitle;
	private TextView mDateText;
	private DatePickerDialog datePickerDialog;
	private FragmentActivity mActivity;
	
	public RecordDateEntry(FragmentActivity mActivity, String title) {
		super(mActivity);
		this.mActivity = mActivity;
		init(mActivity);
		final Calendar calendar = Calendar.getInstance();
		datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 
		calendar.get(Calendar.DAY_OF_MONTH), true);
		mTitle.setText(title);
	}

	public RecordDateEntry(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public RecordDateEntry(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.record_date_selecter_entry, this);
		mTitle = (TextView) view.findViewById(R.id.title);
		mDateText = (TextView) view.findViewById(R.id.recordDatetext);
		mDateText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(mActivity!=null){
					datePickerDialog.setVibrate(true);
			        datePickerDialog.setYearRange(2000, 2016);
			        datePickerDialog.setCloseOnSingleTapDay(false);
			        datePickerDialog.show(mActivity.getSupportFragmentManager(), DATEPICKER_TAG);
				}
			}
		});
	}

	
	public void setEditSize(float size) {
		mDateText.setTextSize(size);
	}

	public void setEditColor(int resId) {
		mDateText.setTextColor(resId);
	}
	
	/**
	 * 
	 */
	public String getDateTextValue() {
		return mDateText.getText().toString().trim();
	}
    /**
     * 
     * @return 获取对应的可以值
     */
	public String getTextViewValue(){
		return mTitle.getText().toString().trim();
	}
	@Override
	public void onDateSet(DatePickerDialog datePickerDialog, int year,
			int month, int day) {
		mDateText.setText(year+"-"+(month+1)+"-"+day);
	}
}
